package com.his.dictorderfreq.controller;

import com.his.config.annotation.CurrentUser;
import com.his.dictorderfreq.entity.DictOrderFreq;
import com.his.dictorderfreq.service.DictOrderFreqService;
import com.his.dictorderfreq.vo.OrderFreqSaveVo;
import com.his.dictorderfreq.vo.OrderFreqVo;
import com.his.login.entity.DictEmployee;
import com.xiao.common.controller.ResultBaseController;
import com.xiao.common.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;


/**
 * @Author zhoufei
 * @Date 2020/3/9
 */


@RestController
@RequestMapping(value="/api/order_freq")
public class DictOrderController extends ResultBaseController{
    private  final Logger logger = (Logger) LoggerFactory.getLogger(this.getClass());
    @Resource
    private DictOrderFreqService dictOrderFreqService;

    @RequestMapping(value="/insert.do")
    public ResultUtil insertDictCode(@CurrentUser DictEmployee dictEmployee,OrderFreqVo orderFreqVo){
        try {
            dictOrderFreqService.insert(orderFreqVo);
            return this.success("保存成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    @RequestMapping(value="/deleteByKey.do")
    public ResultUtil deleteDictCodeByKey(@CurrentUser DictEmployee dictEmployee, OrderFreqVo orderFreqVo){
        try {
            dictOrderFreqService.deleteByKey(orderFreqVo);
            return this.success("成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    @GetMapping("/query_all.do")
    public ResultUtil query(@CurrentUser DictEmployee dictEmployee){
        try {
            List<DictOrderFreq> resultlist = dictOrderFreqService.queryAll(dictEmployee);
            return this.success("",resultlist);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return null;
        }
    }

    @RequestMapping("/update_id.do")
    public ResultUtil updateById(@CurrentUser DictEmployee dictEmployee,@Validated OrderFreqVo orderFreqVo){
        try {
            dictOrderFreqService.updateById(orderFreqVo);
            return this.success("更新成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    @PostMapping("/save.do")
    public ResultUtil save(@CurrentUser DictEmployee dictEmployee,@RequestBody @Validated OrderFreqSaveVo orderFreqSaveVo){
        try {
            dictOrderFreqService.savAll(dictEmployee,orderFreqSaveVo);
            return this.success("更新成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    @GetMapping(value="/get_freq_by_id.do")
    public ResultUtil getOrderFreq(@CurrentUser DictEmployee dictEmployee,String freqId){
        try {
            return this.success("", dictOrderFreqService.selectByFreqId(dictEmployee,freqId));
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
}
